
const white = ['/api/login', '/api/register']
const jwt = require('jsonwebtoken');
module.exports = (options, app) => {
  return async (ctx, next) => {
    if (white.includes(ctx.path)) {
      console.log('我是一个不需要写代码的地方')
      await next()
    } else {
      console.log('我是token的判断区域')
      try { // 捕捉同步代码运行错误
        const { authorization } = ctx.request.headers;
        let data = jwt.verify(authorization, app.config.keys)
        console.log(data, 'data')
        await next()
      } catch (e) {
        ctx.body = {
          code: -1,
          msg: '用户账号或者密码不对'
        }
      }

    }
  }
}